import 'package:get/get.dart';
import 'package:xin_he/page/mine/xin_he_bank_management/xin_he_bank_list_sheet/xin_he_bank_code_entity.dart';

import '../../../../service/xin_he_reqest.dart';
import '../../../../utils/xin_he_toast.dart';
import 'xin_he_bank_list_sheet_state.dart';

class XinHeBankListSheetLogic extends GetxController {
  final XinHeBankListSheetState state = XinHeBankListSheetState();

  RxList list = [
    {'name':'工商银行', 'code':'1002'},
    {'name':'农业银行', 'code':'1005'},
    {'name':'建设银行','code':'1003'},
    {'name':'中国银行','code':'1026'},
    {'name':'招商银行','code':'1001'},
    {'name':'邮政储蓄银行','code':'1066'}  ].obs;

  RxList dataList = [].obs;

  RxInt selectedIndex = 0.obs;
  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();

    selectedIndex.value = 0;

     requestBanksInfo();
  }

  requestBanksInfo() async{


    XinHeRequestDataResult result = await XinHeHttpRequestData.requestUniversalPost(url: '/bankType/queryBankList',isPost: false);

    if(!result.result|| result.data['code'] != 0){
      XinHeToast.center(result.data['message']);
      return ;
    }

    List data = result.data['data'];
    List arr = [];
    if(data.isNotEmpty) {
      for (var e in data) {
        XinHeBankCodeEntity model = XinHeBankCodeEntity.fromJson(e);
        arr.add(model);
      }
    }

    dataList.value = arr;

  }


}
